package simplenote

import (
	"net"
	"time"
)

type timeoutConn struct {
	net.Conn
	timeout time.Duration
}

func (conn *timeoutConn) Read(b []byte) (int, error) {
	if err := conn.SetReadDeadline(time.Now().Add(conn.timeout)); err != nil {
		return -1, err
	}
	return conn.Conn.Read(b)
}

func (conn *timeoutConn) Write(b []byte) (int, error) {
	if err := conn.SetWriteDeadline(time.Now().Add(conn.timeout)); err != nil {
		return -1, err
	}
	return conn.Conn.Write(b)
}
